package net.borlis.processor.dao.entity.common;


import net.borlis.processor.enumerated.ChangeType;

import javax.persistence.*;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by borlis on 24.12.2014.
 */
@MappedSuperclass
public abstract class BaseEntity implements AuditedEntity {

    @Temporal(value = TemporalType.TIMESTAMP)
    @Column(name = "changed_on", nullable = false, columnDefinition = "DATETIME")
    private Date changedOn;

    @Basic
    @Column(name = "changed_by", nullable = false)
    private Long changedBy;

    @Basic
    @Column(name = "changed_type", nullable = false)
    @Enumerated(EnumType.STRING)
    private ChangeType changedType;

    public BaseEntity() {
        this.changedBy = Constants.SYSTEM_USER;
        this.changedOn = Calendar.getInstance().getTime();
        this.changedType = ChangeType.I;
    }

    public Date getChangedOn() {
        return this.changedOn != null ? new Date(this.changedOn.getTime()) : null;
    }

    public void setChangedOn(Date changedOn) {
        this.changedOn = (changedOn != null ? new Date(changedOn.getTime()) : null);
    }

    public Long getChangedBy() {
        return changedBy;
    }

    public void setChangedBy(Long changedBy) {
        this.changedBy = changedBy;
    }

    public ChangeType getChangedType() {
        return changedType;
    }

    public void setChangedType(ChangeType changedType) {
        this.changedType = changedType;
    }
}
